<template>
  <div class="other-swapper">
    <div class="menu-box">
      <el-button icon="el-icon-check" @click="onSubmit">立即创建</el-button>
    </div>
    <el-form :model="form" ref="form" label-width="120px">
      <el-row :gutter="24">
        <el-col :span="8">
          <el-form-item label="开售时间">
            <el-date-picker style="width:100%" v-model="form.startSaleDate" type="datetime" value-format="timestamp" placeholder="请选择开售时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="倒计时开始时间">
            <el-date-picker style="width:100%" v-model="form.countdownDate" type="datetime" value-format="timestamp" placeholder="请选择倒计时开始时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="限购数量设置">
            <el-input-number style="width:100%" v-model="form.limitNum" :step="1" controls-position="right" :min="1"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="限购邮箱设置">
            <el-input v-model.trim="form.connectEmail" placeholder="请输入限购邮箱设置"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="客服电话">
            <el-input-number style="width:100%" v-model="form.customerServiceTel" :controls="false" :step="1" controls-position="right" :min="1"></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

  </div>
</template>

<script>
export default {
  data() {
    return {
      // form:{
      //   activityId: this.$store.state.activityId,
      //   startSaleDate: '',
      //   countdownDate: '',
      //   limitNum: '',
      //   connectEmail: '',
      //   customerServiceTel: '',
      // }
      form: {}
    };
  },
  created() {
    this.queryById();
  },
  methods: {
    queryById() {
      this.$http
        .post("/api/isv/activity/queryActivityById", {
          activityId: this.$store.state.activityId
        })
        .then(
          res => {
            if (res.data.success) {
              this.form = res.data.result;
            } else {
              this.$message({
                message: res.data.errorMsg || "数据获取失败",
                type: "warning"
              });
            }
          },
          err => {
            this.$message.error("服务器出小差了");
          }
        );
    },
    onSubmit() {
      this.form.endDate = this.form.enddate;
      let regu = /@/;
      let re = new RegExp(regu);
      if (this.form.connectEmail && !re.test(this.form.connectEmail)) {
        this.$message({
          message: "请填写正确邮箱",
          type: "warning"
        });
        return;
      }
      this.$http.post("/api/isv/activity/updateOtherSet", this.form).then(
        res => {
          if (res.data.success) {
            this.$message({
              type: "success",
              message: "创建成功!"
            });
            this.queryById();
          } else {
            this.$message({
              message: res.data.errorMsg || "数据提交失败",
              type: "warning"
            });
          }
        },
        err => {
          this.$message.error("服务器出小差了");
        }
      );
    }
  }
};
</script>

<style scoped>
.other-swapper {
  width: 100%;
  background: #fff;
  border-radius: 6px;
  padding: 26px 26px;
}
.menu-box {
  text-align: right;
  padding-bottom: 20px;
}
</style>
